package com.backend.modules.system.controller;

import com.backend.common.model.R;
import com.backend.modules.system.convert.UserConvert;
import com.backend.modules.system.dto.UpdatePasswordDto;
import com.backend.modules.system.dto.UserQueryDTO;
import com.backend.modules.system.dto.UserUpdateDTO;
import com.backend.modules.system.service.SysUserService;
import com.backend.modules.system.vo.UserVO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springdoc.api.annotations.ParameterObject;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@Tag(name = "用户管理", description = "用户管理相关接口")
@RestController
@RequestMapping("/v1/users")
@RequiredArgsConstructor
public class UserController {

    private final SysUserService userService;


    @Operation(summary = "获取当前用户信息")
    @GetMapping("/current")
    public R<UserVO> getCurrentUser() {
        return R.ok(UserConvert.convert(userService.getCurrentUser()));
    }



    @Operation(summary = "更新当前用户信息")
    @PutMapping("/current")
    public R<Void> updateCurrentUser(@Validated @RequestBody UserUpdateDTO dto) {
        userService.updateCurrentUser(dto);
        return R.ok();
    }
    @Operation(summary = "修改密码")
    @PutMapping("/password")
    public R<Void> updatePassword(@Validated @RequestBody UpdatePasswordDto dto) {
        userService.updatePassword(dto);
        return R.ok();
    }
}